package com.dubbo.boot.consumer.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dubbo.bean.Order;
import com.dubbo.service.OrderService;
import com.dubbo.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author by Mr. Li 2020/11/20 14:30
 */
@Service
public class OrderServiceImpl implements OrderService {

    //@Autowired 消费服务 dubbo 提供了专门的注解
    @Reference(url = "127.0.0.1:20880")// dubbo直连
    private UserService userService;


    @Override
    @HystrixCommand(fallbackMethod = "helloHystrix")
    public List<Order> initOrder(int userId) {
        // 调用远程的user服务 获取order地址
        List<Order> userAddressList = userService.getUserAddressList(userId);
        System.out.println(userAddressList);
        return userAddressList;
    }

    public List<Order> helloHystrix(int userId) {
        return Collections.singletonList(new Order(userId, "测试", "测试", "12345743864314"));
    }
}
